﻿// <copyright file="AppNotificationSenderFactory.cs" company="Robert Venables">
// Copyright (c) 2009 Robert Venables.
// </copyright>
// <author>Robert Venables</author>
// <email>rob@rvenables.com</email>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace VNotify
{
    /// <summary>
    /// Constructs well formed AppNotificationSender objects.
    /// </summary>
    /// <typeparam name="TSender">The type of IAppNotificationSender to construct.</typeparam>
    internal class AppNotificationSenderFactory<TSender>
        : IAppNotificationSenderFactory
        where TSender : IAppNotificationSender, new()
    {
        /// <summary>
        /// Builds an IAppNotificationSender with the specified API key.
        /// </summary>
        /// <param name="apiKey">The API key to use to construct the sender.</param>
        /// <returns>A correctly constructed IAppNotificationSender.</returns>
        public virtual IAppNotificationSender BuildSender(string apiKey)
        {
            if (string.IsNullOrEmpty(apiKey) || apiKey.Length < 4)
                throw new ArgumentException("API Key");

            TSender notificationSender = new TSender();
            notificationSender.Initialize(apiKey);
            return notificationSender;
        }
    }
}
